package opreation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOpreation implements IOpreation{

    @Override
    public void work(BookList booklist) {

        System.out.println("新增图书");

        System.out.println("请输入需要添加的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = booklist.getUsedsize();//3
        for (int i = 0; i < size; i++) {
            Book tmp = booklist.getBooks(i);//拿到一本书的地址
            if(tmp.getName().equals(name)) {
                System.out.println(name+"重复添加");
                return;
            }
        }
        System.out.println("请需要添加的书的作者：");
        String auther = scanner.nextLine();

        System.out.println("需要添加的书的价格：");
        int price = scanner.nextInt();
       scanner.nextLine();//吸收空格

        System.out.println("需要添加的书的的类型：");
        String type = scanner.nextLine();

        Book book= new Book(name,auther,price,type);

        booklist.setBooks(book,size);
        booklist.setUsedsize(size+1);
        System.out.println("增加成功");
    }
}
